<template>
  <div class="file-extract-node-card" ref="card">
    <!-- 删除蓝点锚点相关代码 -->
    <div class="header">
      <span class="icon"></span>
      <span class="title">文件内容提取节点</span>
    </div>
    <div class="desc">从文件中提取文本内容</div>
    <div class="section-title">文件配置</div>
    <div class="config-list">
      <div class="config-row">
        <label>文件路径：</label>
        <el-input v-model="localConfig.filePath" size="small" placeholder="请输入文件路径或变量名" @input="emitChange" />
      </div>
      <div class="config-row">
        <label>文件类型：</label>
        <el-select v-model="localConfig.fileType" size="small" style="width: 100%;" @change="emitChange">
          <el-option label="自动检测" value="auto" />
          <el-option label="PDF" value="pdf" />
          <el-option label="Word文档" value="docx" />
          <el-option label="Excel表格" value="xlsx" />
          <el-option label="文本文件" value="txt" />
          <el-option label="CSV文件" value="csv" />
          <el-option label="JSON文件" value="json" />
        </el-select>
      </div>
      <div class="config-row">
        <label>编码格式：</label>
        <el-select v-model="localConfig.encoding" size="small" style="width: 100%;" @change="emitChange">
          <el-option label="UTF-8" value="utf8" />
          <el-option label="GBK" value="gbk" />
          <el-option label="GB2312" value="gb2312" />
          <el-option label="自动检测" value="auto" />
        </el-select>
      </div>
    </div>
    <div class="section-title">提取配置</div>
    <div class="config-list">
      <div class="config-row">
        <label>提取模式：</label>
        <el-select v-model="localConfig.extractMode" size="small" style="width: 100%;" @change="emitChange">
          <el-option label="全文提取" value="full" />
          <el-option label="按页提取" value="page" />
          <el-option label="按段落提取" value="paragraph" />
          <el-option label="按表格提取" value="table" />
        </el-select>
      </div>
      <div class="config-row" v-if="localConfig.extractMode === 'page'">
        <label>页码范围：</label>
        <el-input v-model="localConfig.pageRange" size="small" placeholder="如：1-5,8,10-15" @input="emitChange" />
      </div>
      <div class="config-row">
        <el-checkbox v-model="localConfig.includeMetadata" @change="emitChange">包含元数据</el-checkbox>
      </div>
      <div class="config-row">
        <el-checkbox v-model="localConfig.includeFormatting" @change="emitChange">保留格式</el-checkbox>
      </div>
    </div>
    <div class="section-title">输出配置</div>
    <div class="config-list">
      <div class="config-row">
        <el-checkbox v-model="localConfig.saveToVariable" @change="emitChange">保存到变量</el-checkbox>
      </div>
      <div class="config-row" v-if="localConfig.saveToVariable">
        <label>变量名：</label>
        <el-input v-model="localConfig.outputVariable" size="small" placeholder="请输入输出变量名" @input="emitChange" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'FileExtractNodeCard',
  props: {
    config: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      localConfig: { ...this.config }
    }
  },
  watch: {
    config: {
      handler(newVal) {
        this.localConfig = { ...newVal }
      },
      deep: true
    }
  },
  methods: {
    emitChange() {
      this.$emit('change', { ...this.localConfig })
    },
    addHeader() {
      this.config.headers.push({ key: '', value: '' });
    },
    removeHeader(idx) {
      this.config.headers.splice(idx, 1);
    }
  }
};
</script>

<style scoped>
.file-extract-node-card {
  width: 300px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 2px 8px 0 rgba(0,0,0,0.04);
  padding: 16px;
  position: relative;
}

.node-dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2979ff;
  border: 2px solid #fff;
  box-shadow: 0 0 2px #2979ff;
  cursor: pointer;
  z-index: 10;
  transition: box-shadow 0.2s;
}

.node-dot--left-top {
  top: -6px;
  left: -6px;
}

.node-dot--right-top {
  top: -6px;
  right: -6px;
}

.node-dot:hover {
  box-shadow: 0 0 8px #2979ff;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  position: relative;
}

.icon {
  width: 32px;
  height: 32px;
  background: #e1f5fe;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  position: relative;
}

.icon::after {
  content: '📄';
  display: block;
  width: 16px;
  height: 16px;
  font-size: 16px;
  position: absolute;
  left: 8px;
  top: 8px;
}

.title {
  font-size: 18px;
  font-weight: bold;
}

.desc {
  color: #888;
  font-size: 13px;
  margin-bottom: 8px;
}

.section-title {
  font-weight: bold;
  margin-bottom: 8px;
  margin-top: 12px;
}

.section-title:first-of-type {
  margin-top: 0;
}

.config-list {
  background: #fafbfc;
  border-radius: 6px;
  padding: 12px;
}

.config-row {
  margin-bottom: 12px;
}

.config-row:last-child {
  margin-bottom: 0;
}

.config-row label {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  color: #333;
}
</style> 